package com.geekstudy.week4.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxyInterceptorEnhancer {

    public DynamicEnhancer enhance(Object target, Class interfaceClass) {
        String name = DynamicProxyInvocationContext.defaultTargetName(target);

        InvocationHandler invocationHandler = new InvocationHandler()  {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return method.invoke(target, args);
            }
        };

        DynamicEnhancer dynamicEnhancer = new DynamicEnhancer(name, target, interfaceClass, invocationHandler);
        return dynamicEnhancer;
    }
}
